package cn.android666.getip

import android.annotation.SuppressLint
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import cn.android666.getip.databinding.ActivityMainBinding
import timber.log.Timber

class MainActivity : AppCompatActivity() {

    private val binding by lazy { ActivityMainBinding.inflate(layoutInflater) }

    @SuppressLint("SetTextI18n")
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(binding.root)
        binding.button.setOnClickListener {
            val start = System.currentTimeMillis()
            val info = """
                当前正在使用的网络接口如下：
                ${NetUtil.getNetInterface()}，用时：${System.currentTimeMillis() - start}ms
                所有网络接口如下：
                ${NetUtil.getNetInterfaceList().joinToString("\n")}
                wifi routeIp=${NetUtil.getWifiRouteIpAddress()}
                """.trimIndent()

            binding.textView.text = info

            Timber.i(info)
            Timber.i("详细的所有网络接口如下：")
            NetUtil.printAllInterfaces()
        }
    }

}